<?php
/*********************************************************************************
* Filename: team_verification.php
* 
* A page that authenticates the given team or displays an error message
* if the passed-in authentication code is invalid.
*
*
* Author: Caleb Goff
* Date Created: 10/12/2009
**********************************************************************************/

//The common.php file contains 
include_once "common.php";

echo "$header_open";
echo "$css_create";
echo "$js_team_home";
echo "$header_close";

?>

<body>

<div id="wrapper">
	<div id="inner">
		<div id="masthead">
			<h1>
			</h1>
			<ul>
				<?php 
					echo"$g_nav_bar";
				?>
			</ul>
		</div>

	    	<div id="all_content">
			<h2>
				Team Confirmation
			</h2>
			<?php
                // Grab the team key, compare against VERIFY table
				$key = $_GET['key'];
				
				$query = "SELECT TEAM_ID
					  FROM VERIFY
					  WHERE VERIFY_KEY = '$key'";

				$results = do_query($query, $g_db_name, $g_username);
				
				$row = mysql_fetch_assoc($results);

                // If we get a result, delete it from database and notify
                // user that the team is validated.
				if (mysql_num_rows($results) > 0)
				{
					$team_id = $row['TEAM_ID'];
					$query = "DELETE FROM VERIFY WHERE TEAM_ID = $team_id";
					do_query($query,$g_db_name,$g_username);
					echo "You have successfully confirmed your team! You can now <a href='index.php'>log in</a> on the 
                          homepage to manage your team.\n";
				} else {
                    // If no team is found, display a message to the user
					echo "This is not a recognized verification key! Please use the link provided in your email to confirm you team.";
				}
			?>
		</div>

		<h2></h2>

		<div id="footer">
			<?php echo "$footer"; ?>
		</div>

	</div>    

</div>
</body>
</html>
